<template>
    <div>
        <el-button type="primary" style="position: relative;left: 700px" @click="addPB">添加排班</el-button>
    <div>
        <el-row>
            <el-col :span="24"><div>
                <el-input v-model="true_name" placeholder="请输入医生名称" style="width: 300px"></el-input>
                <el-button type="primary" @click="list">检索</el-button>
            </div></el-col>
        </el-row>
        <el-table
                :data="tableData" style="width: 800px;">
            <el-table-column
                    prop="trueName"
                    label="姓名">
            </el-table-column>
            <el-table-column
                    prop="age"
                    label="姓名">
            </el-table-column>
            <el-table-column
                    prop="sex"
                    label="性别">
                <template slot-scope="scope">
                    {{scope.row.sex==0?'男':'女'}}
                </template>
            </el-table-column>
            <el-table-column
                    prop="department_name"
                    label="科室">
                <template slot-scope="scope">
                    {{scope.row.hisMemberEntities.hisDepartmentEntities.departmentName}}
                </template>
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
        <div>
            <el-dialog
                    :visible.sync="status1" width="600px">
                <el-form ref="form" :model="form" label-width="80px" style="margin-right: 50px">
                    <el-form-item label="医生">

                        <el-select v-model="form.physicianid" placeholder="请选择医生" @change="c(form.physicianid)"  >
                            <el-option v-for="t in allDoctor" :key="t.id" :value="t.id" :label="t.trueName"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="科室">
                        <el-select v-model="form.departmentId" >
                            <el-option v-for="d in allDe" :key="d.did" :value="d.did" :label="d.departmentName"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="开始时间">
                        <el-date-picker
                                v-model="form.startTimeThisWeek"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd" >
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="结束时间">
                        <el-date-picker
                                v-model="form.endTimeThisWeek"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </el-form-item>

                    <el-form-item label="时间">
                        <el-tree
                                :data="AllSources"
                                show-checkbox
                                node-key="id"
                                highlight-current
                                :default-checked-keys="Sources"
                                :props="defaultProps"
                                @check-change="getChecked"
                                ref="tree" style="margin-left: 50px;margin-top: 20px">
                        </el-tree>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">确认</el-button>
                    </el-form-item>
                </el-form>
            </el-dialog>
        </div>
        <div>
            <el-dialog
                    :visible.sync="status" width="600px">
                <el-table
                        :data="tableData2" style="width: 800px;">
                    <el-table-column
                            prop="startTimeThisWeek"
                            label="本周开始时间">
                    </el-table-column>
                    <el-table-column
                            prop="endTimeThisWeek"
                            label="本周结束时间">
                    </el-table-column>
                    <el-table-column
                            fixed="right"
                            label="操作">
                        <template slot-scope="scope">
                            <el-button @click="handleClick2(scope.row)" type="text" size="small">查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-dialog>
        </div>
        <el-dialog title="医生挂号时间" :visible.sync="dialogFormVisibledate">
        <el-table
                :data="tableData3"
                border
                style="width: 100%">
            <el-table-column
                    label="工作时间">
                <template slot-scope="scope" >
                    {{scope.row.subsectionType=='1'?'上午':scope.row.subsectionType=='2'?'中午':'晚上'}}
                </template>
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="lookdate1(scope.row)" type="text" size="small">查看工作时间</el-button>
                </template>
            </el-table-column>
        </el-table>
    </el-dialog>

        <el-dialog title="医生周期" :visible.sync="dialogFormVisibledate1">
            <el-table
                    :data="tableData4"
                    border
                    style="width: 100%">
                <el-table-column
                        label="工作时间">
                    <template slot-scope="scope" >
                        {{scope.row.week==1?'星期一':(scope.row.week==2?'星期二':(scope.row.week==3?'星期三':(scope.row.week==4?'星期四':(scope.row.week==5?'星期五':(scope.row.week==6?'星期六':'星期天')))))}}

                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
    </div>
</template>

<script>
    import  DoctorManage from  '../../model/ww/DoctorManage'
    const  doctormanage=DoctorManage.getInstance();
    import  Scheduling from  '../../model/ww/Scheduling'
    const  scheduling =Scheduling.getInstance();
    export default {
        name: "Scheduling",
        data(){
            return {
                tableData:[], //医生信息,
                status:false,//状态
                dialogFormVisibledate:false,
                dialogFormVisibledate1:false,
                tableData2:[],
                tableData3:[],
                tableData4:[],
                true_name:'',
                status1:false, //添加排班状态
                form:{
                    hisSchedulingSubsectionEntities:[
                        {
                            schedulingSubsectionId:'',
                            subsectionType:'1',
                            schedulingId:'',
                            hisSchedulingWeekEntity:[]
                        },
                        {
                            schedulingSubsectionId:'',
                            subsectionType:'2',
                            schedulingId:'',
                            hisSchedulingWeekEntity:[]
                        },
                        {
                            schedulingSubsectionId:'',
                            subsectionType:'3',
                            schedulingId:'',
                            hisSchedulingWeekEntity:[]
                        }
                    ]
                },   //添加的排班用户信息
                allDoctor:[],
                allDe:[],
                timeDate:[],
                status3:true,
                defaultProps: { //所有资源
                    children: 'children',
                    label: 'label'
                },
                AllSources:[
                    {
                        id:1,
                        label:'上午',
                        children:[
                            {id:11, label:'星期一'},
                            {id:12, label:'星期二'},
                            {id:13, label:'星期三'},
                            {id:14, label:'星期四'},
                            {id:15, label:'星期五'},
                            {id:16, label:'星期六'},
                            {id:10, label:'星期日'}
                        ]
                    },
                    {
                        id:2,
                        label:'下午',
                        children:[
                            {id:21, label:'星期一'},
                            {id:22, label:'星期二'},
                            {id:23, label:'星期三'},
                            {id:24, label:'星期四'},
                            {id:25, label:'星期五'},
                            {id:26, label:'星期六'},
                            {id:20, label:'星期日'}
                        ]
                    },
                    {
                        id:3,
                        label:'晚上',
                        children:[
                            {id:31, label:'星期一'},
                            {id:32, label:'星期二'},
                            {id:33, label:'星期三'},
                            {id:34, label:'星期四'},
                            {id:35, label:'星期五'},
                            {id:36, label:'星期六'},
                            {id:30, label:'星期日'}
                        ]
                    },
                ],
                Sources:[],
                aa:[],
                form2:{}

            }
        },
        methods:{
            list(){
                doctormanage.list(this.true_name).then((response)=>{
                     this.tableData=response.data.data  //查看所有医生信息

                    this.tableData.forEach(i=>{
                        this.allDoctor.push({id:i.id,trueName:i.trueName})
                    })
                })

            },

            handleClick(row){//查看排班
                this.status=!this.status
                scheduling.list(row.id).then((response)=>{
                    this.tableData2=response.data.data
                })
            },
            handleClick2(row){
                this.dialogFormVisibledate=!this.dialogFormVisibledate
                this.tableData3=row.hisSchedulingSubsectionEntities

            },
            lookdate1(row){
                this.dialogFormVisibledate1=!this.dialogFormVisibledate1
                this.tableData4=row.hisSchedulingWeekEntity
            },
            addPB(){ //添加排班
               this.status1=!this.status1
            },
            c(a){
              this.tableData.forEach(i=>{
                  if(i.id==a){
                      this.allDe=[]
                     this.allDe.push({did:i.hisMemberEntities.hisDepartmentEntities.did,departmentName:i.hisMemberEntities.hisDepartmentEntities.departmentName})
                  }
              })
            }
            ,
            onSubmit(){//提交aa
                //判断是否已经拍过班了
                this.form2.endTimeThisWeek=this.form.endTimeThisWeek
                this.form2.startTimeThisWeek=this.form.startTimeThisWeek
                this.form2.physicianid=this.form.physicianid
                scheduling.testPB(this.form2).then((response)=>{
                    console.log(response.data.message)
                    if(response.data.message=='错误'){
                        this.$message("该医生近一周已经排过班啦!")
                        return;
                    }
                })
                this.aa.forEach(i=>{
                     this.form.hisSchedulingSubsectionEntities.forEach(j=>{
                         if(i>=10 && i<=16 && j.subsectionType==1){
                             j.hisSchedulingWeekEntity.push({schedulingWeekId:'',date:'',week:i,registeredfeeId:'',schedulingSubsectionId:''})
                         }
                         if(i>=20 && i<=26 && j.subsectionType==2){
                             j.hisSchedulingWeekEntity.push({schedulingWeekId:'',date:'',week:i,registeredfeeId:'',schedulingSubsectionId:''})
                         }
                         if(i>=30 && i<=36 && j.subsectionType==3){
                             j.hisSchedulingWeekEntity.push({schedulingWeekId:'',date:'',week:i,registeredfeeId:'',schedulingSubsectionId:''})
                             // this.form.hisSchedulingSubsectionEntities.push({schedulingSubsectionId:'',subsectionType:3,hisSchedulingWeekEntity:[{schedulingWeekId:'',date:'',week:i,registeredfeeId:'',schedulingSubsectionId:''}]})
                         }
                     })
                })

                scheduling.addPB(this.form).then(()=>{
                    this.status1=!this.status1
                    this.aa=[]
                })

            }
            ,
            getChecked(){
                const childrenIds = this.$refs.tree.getCheckedKeys()
                this.aa=childrenIds
            }



        },
        created() {
            this.list()

        }
    }
</script>

<style scoped>

</style>